package com.syncy.process.states;

import java.util.Arrays;

import com.syncy.process.ProcessStateAction;
import com.syncy.process.ProcessStatus;
import com.syncy.process.exceptions.WrongStateException;

public abstract class ProcessState {
	
	protected ProcessStatus status = null;

	public final void setState(ProcessStateAction action){
		
		if(isActionValid(action)){
			this.status = doTransition(action);
		} else {
			throw new WrongStateException(action);
		}
		
	}
	
	protected boolean isActionValid(ProcessStateAction action){
		
		ProcessStateAction[] validActions = getValidActions();
		boolean b = Arrays.asList(validActions).contains(action);
		return b;
	}
	
	public abstract ProcessStateAction[] getValidActions();
	
	public abstract ProcessStatus doTransition(ProcessStateAction action);
	
	public final ProcessStatus getStatus() {
		return this.status;
	}
	
}
